<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">

<th:block th:include="include :: header('分类列表')" />
<th:block th:include="include :: select2-css" />
<style type="text/css">
	.ellipsis .btn-group {
		position: absolute;
		margin-top: -10px;
	}
</style>

<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="cat-form">
					<div class="select-list">
						<ul>
							<li>
								<p>类目名称：</p> <input class="form-control" type="text" name="catName" />
							</li>
							<li>
								<p>类目ID：</p> <input class="form-control" type="text" name="catId" />
							</li>
							<li>类目状态：<select class="form-control" name="visible"
									th:with="type=${@dictTag.getType('cms_cat_visible')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:value="${dict.dictValue}"
										th:text="${dict.dictLabel}">显示</option>

								</select>
							</li>
							<li>类目类型：<select class="form-control" name="catType"
									th:with="type=${@dictTag.getType('cms_support_type')}">
									<option value="">所有</option>
									<option th:each="dict : ${type}" th:value="${dict.dictValue}"
										th:text="${dict.dictLabel}"></option>

								</select>
							</li>
							<li>分类所属：<select class="form-control" name="params[supportType]">
									<option value="">所有</option>
									<option th:each="themeName: ${themeNames}" th:text="${themeName}"
										th:value="${themeName}">
								</select>
							</li>
							<li class="select-time"><label>创建时间： </label> <input type="text" class="time-input"
									id="startTime" placeholder="开始时间" name="params[beginTime]" /> <span>-</span> <input
									type="text" class="time-input" id="endTime" placeholder="结束时间"
									name="params[endTime]" /></li>
							<li><a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
										class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
										class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>

			<div class="btn-group-sm" id="toolbar" role="group">
				<div class="btn-group" shiro:hasPermission="cms:cat:edit">
					<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle">状态 <span
							class="caret"></span>
					</button>
					<ul class="dropdown-menu" id="catVisible" th:with="type=${@dictTag.getType('cms_cat_visible')}">
						<li th:each="dict : ${type}" th:data-id="${dict.dictValue}"><a href="javascript:void(0)"
								th:text="${dict.dictLabel}"></a></li>
					</ul>
				</div>
				<a class="btn btn-success" onclick="$.operate.add(0)" shiro:hasPermission="cms:cat:add"> <i
						class="fa fa-plus"></i>
					新增
				</a> <a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="cms:cat:edit"> <i
						class="fa fa-edit"></i>
					修改
				</a> <a class="btn btn-info" id="expandAllBtn"> <i class="fa fa-exchange"></i> 展开/折叠
				</a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>

	<div th:include="include :: footer"></div>
	<th:block th:include="include :: select2-js" />
	<script th:inline="javascript">
		var addFlag = [[${@permission.hasPermi('cms:cat:add') }]];
		var editFlag = [[${@permission.hasPermi('cms:cat:edit') }]];
		var removeFlag = [[${@permission.hasPermi('cms:cat:remove') }]];
		var v = [[${@dictTag.getType('cms_cat_visible') }]];
		var p = [[${@dictTag.getType('cms_cat_parent') }]];
		var t = [[${@dictTag.getType('cms_support_type') }]];
		var prefix = ctx + "cms/cat";

		$(function () {
			var options = {
				code: "catId",
				parentCode: 'parentId',
				uniqueId: "catId",
				expandAll: false,
				expandFirst: false,
				url: prefix + "/list",
				createUrl: prefix + "/add/{id}",
				updateUrl: prefix + "/edit/{id}",
				removeUrl: prefix + "/remove/{id}",
				modalName: "内容类目",
				columns: [{
					field: 'selectItem',
					radio: true
				}, {
					field: 'catId',
					title: '类目Id'
				},
				{
					field: 'catIcon',
					title: '图标',
					formatter: function (value, row, index) {
						if ($.common.isEmpty(value)) {
							return '<span class="card-view-value undefined">-</span>';
						}
						else
						return $.table.imageView(value);
					}
				},
				{
					title: '类目名称',
					field: 'catName'
				},
				{
					field: 'parent',
					title: '节点类型',
					align: "left",
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(p, value);
					}
				},
				{
					field: 'catType',
					title: '类目类型',
					align: "left",
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(t, value);
					}
				},
				{
					field: 'catCount',
					title: '关联文章',
					lign: "left",
					formatter: function (value, row, index) {
						return value == null ? 0 : value;
					}
				},
				{
					field: 'createBy',
					title: '创建人Id'
				},
				{
					field: 'catUrl',
					title: '类目路径',
					align: "left",
					visible: false
				},
				{
					field: 'orderNum',
					title: '排序',
					align: "left"
				},
				{
					field: 'keywords',
					title: '关键词',
					align: "left",
					visible: false
				},
				{
					field: 'description',
					title: '描述',
					align: "left",
					visible: false
				},
				{
					field: 'visible',
					title: '状态',
					align: "left",
					formatter: function (value, row, index) {
						return $.table.selectDictLabel(v, value);
					}
				},
				{
					field: 'createTime',
					title: '创建时间',
					sortable: true
				},
				{
					title: '操作',
					align: "left",
					formatter: function (value, row, index) {
						var actions = [];
						actions.push('<a class="' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.catId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
						actions.push('<a class="' + editFlag + '" href="#" onclick="relation(\'' + row.catId + '\')"><i class="fa fa-eye"></i>查看关联</a> ');
						actions.push('<a class="' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.catId + '\')"><i class="fa fa-trash"></i>删除</a>');
						if (row.parent == 0) {
							actions.push('<a class="' + addFlag + '" href="#" onclick="$.operate.add(\'' + row.catId + '\')"><i class="fa fa-plus"></i>添加下级类目</a>');
						}
						return $.table.dropdownToggle(actions.join(''));
					}
				}]
			};
			$.treeTable.init(options);
		});
		//修改分类状态
		$('#catVisible>li').click(function (e) {
			//获取选中的行
			var pam = {}, chooseData = $("#" + table.options.id).bootstrapTreeTable('getSelections');
			if (chooseData.length > 0) {
				pam.catId = chooseData[0].catId;
				pam.visible = $(this).attr("data-id");
				$.modal.confirm("确认要修改选的类目状态吗？子节点将修改为一样的状态！", function () {
					$.operate.post(prefix + "/editCatVisible", pam);
				})
			}
			else {
				$.modal.alert("请选择一项");

			}
		});

		function relation(catId) {
			$.modal.openTab("查看关联文章", prefix + "/relation/" + catId);
		}
	</script>
</body>

</html>